package jnpf.engine.util;

import jnpf.engine.model.flowmessage.FlowParameterModel;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 事件数据添加
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司
 * @date 2022/8/20 8:49
 */
public class FlowContextHolder {

    private static final ThreadLocal<List<FlowParameterModel>> CONTEXT_DB_NAME_HOLDER = new ThreadLocal<>();

    /**
     * 初始化数据
     */
    public static void initEvent() {
        List<FlowParameterModel> list = new ArrayList<>();
        CONTEXT_DB_NAME_HOLDER.set(list);
    }

    /**
     * 添加当前事件对象
     */
    public static void addEvent(String interId, Map<String, String> parameterMap) {
        FlowParameterModel model = new FlowParameterModel();
        model.setInterId(interId);
        model.setParameterMap(parameterMap);
        List<FlowParameterModel> list = CONTEXT_DB_NAME_HOLDER.get();
        if (list == null) {
            list = new ArrayList<>();
            CONTEXT_DB_NAME_HOLDER.set(list);
        }
        list.add(model);
    }

    /**
     * 获取当前事件对象
     */
    public static List<FlowParameterModel> getAllEvent() {
        return CONTEXT_DB_NAME_HOLDER.get();
    }

    /**
     * 清除数据
     */
    public static void clearEvent() {
        CONTEXT_DB_NAME_HOLDER.remove();
    }

}
